package com.liangzhong.model.friend.vo
{
	import com.liangzhong.constants.ResourceConst;
	import com.liangzhong.manager.ResourceManager;

	/**
	 *好友荣誉信息 
	 * @author lake
	 * 
	 */	
	public class FriendHonorVo
	{
		/**
		 * 天梯记录
		 */		
		public var tt_record 			:int;
		/**
		 * 连胜记录
		 */		
		public var winstreak_history 	:int;
		/**
		 * 不败记录
		 */		
		public var unbeaten_history		:int;
		/**
		 * 当前连胜记录
		 */		
		public var winstreak			:int;
		/**
		 *荣誉列表 
		 */		
		public var ttHonourList			:Array;
		/**
		 *成就 
		 * {t1:1,t2:0,t3:1,...}
		 */		
		private var achieve				:Object;
		/**
		 *显示的列表 
		 */		
		private var _achieveList			:Array;
		
		public function FriendHonorVo()
		{
		}
		/**
		 *解析数据 
		 * @param data
		 */		
		public function parse(data :Object):void
		{
			var info :Object 		= data.info;
			tt_record 				= info.tt_record;
			winstreak_history 		= info.winstreak_history;
			unbeaten_history 		= info.unbeaten_history;
			winstreak 				= info.winstreak;
			///
			var ttList :Array 		= data.tt_honour;//[{period:10,level:25,sort:1}];
			var friendHonourItemVo :FriendHonourItemVo;
			ttHonourList = [];
			_achieveList = [];
			var tXml :XML = getHonourXmlInfo("t0");
			var itemXML :XML ;
			for each(var item :Object in ttList)
			{
				itemXML = tXml.copy();
				friendHonourItemVo = new FriendHonourItemVo();
				friendHonourItemVo.parse(item);
				itemXML.iconId = itemXML.iconId + "_" + friendHonourItemVo.sort;
				itemXML.tips = friendHonourItemVo.tips;
				ttHonourList.push(friendHonourItemVo);
				_achieveList.push(itemXML);
			}
			///achieve
			achieve = data.achieve;
			//
			for(var key :* in achieve)
			{
				if(achieve[key] == 1)
				{
					_achieveList.push(getHonourXmlInfo(key));
				}
			}
		}
		/**
		 *获取激活的成就 
		 * @return 
		 * 
		 */		
		public function get achieveList():Array
		{
			return _achieveList;
		}
		
		public function getHonourXmlInfo(type :*):XML
		{
			var rXml :XML;
			var hXml :XML = ResourceManager.instance.getResource(ResourceConst.CLUB_HONOUR);
			if(hXml == null)
			{
				return rXml;
			}
			for each(var item :XML in hXml.item)
			{
				if(item.type == type)
				{
					rXml = item;
					break;
				}
			}
			return rXml;
		}
	}
}